<template>
  <div class="box">
    <Region :stockTabs="stockTabs" v-if="isRegion"></Region>
    <div class="container container--zone">
      <div class="region region--full removeLive">
        <comImg :imgData="imgData"></comImg>
        <!-- <tabText :moreList="moreList" :listlinkData="listlinkData" @tabChange="tabChange"></tabText> -->
        <div style="width:100%;border-top:1px solid #e1e1e1;margin-bottom:15px;"></div>
      </div>
    </div>
    <textBottomCont :bigImgData='bigImgData' :asideoneImg='asideoneImg' :asidebulletsData="asidebulletsData"
      :asideArticleData="asideArticleData" :bulletsData='bulletsData' :botfullData='botfullData' v-if="isTextBc">
    </textBottomCont>
    <mastPopular></mastPopular>
    <theVideo></theVideo>
    <watchList></watchList>
    <!-- <newSetter></newSetter> //广告先不要 -->
    <fourTitleImg></fourTitleImg>
    <adverTiseMent></adverTiseMent>
  </div>
</template>

<script setup>
import Region from "./home/region/region.vue";
import comImg from "../components/comImg/comImg.vue";
import tabText from "../components/tabText/tabText.vue";
import textBottomCont from "./home/textBottomCont/textBottomCont.vue"; //最受欢迎的上面模块
import mastPopular from "./home/mastPopular/mastPopular.vue"; //最受欢迎模块
import theVideo from "./home/theVideo/theVideo.vue"; //播放视频的模块
import watchList from "./home/watchList/watchList.vue";
// import newSetter from "./home/newSetter/newSetter.vue";
import fourTitleImg from "./home/fourTitleImg/fourTitleImg.vue";
import adverTiseMent from "./home/adverTisement/adverTiseMent.vue";

const imgData = ref("../src/assets/banner.png");

const moreList = reactive([]);
const listlinkData = ref([])
// 请求首页数据
import homeRequest from "@/api/home.js";
import loginRequest from "@/api/login.js";
let stockTabs = reactive([]);
const isRegion = ref(false)
const newsList = ref([])
const isTextBc = ref(false)
const latestNews = ref([])
const mdList = ref([])
onMounted(() => {

  const data = localStorage.getItem('tabMdData')
  if (data) {
    listlinkData.value = JSON.parse(data).home
  }
  //指数数据
  homeRequest.regionData({})
    .then((res) => {
      if (res.code == "0") {
        stockTabs = res.data.stockTabs;
        isRegion.value = true
      }
    })
    .catch((e) => {
    });
  getNewList()
  getHomeList()
});
const tabChange = () => { }
// 新闻列表 头部左边大图stcoks关键字部分
const getNewList = () => {
  let data = {
    current: 1,
    size: 50,
    isImg: 1,
    key: 'stocks'
  }
  homeRequest.newsData(data)
    .then((res) => {
      if (res.code == "0") {
        mdList.value = res.data.records
      }
    })
    .catch((e) => {
    });
}

const bigImgData = ref([])
const bulletsData = ref([])
const asideoneImg = ref({})
const asidebulletsData = ref([])
const asideArticleData = ref([])
const botfullData = ref([])
const getHomeList = () => {
  let data = {
    key: "index"
  }
  homeRequest.homeNew(data)
    .then((res) => {
      if (res.code === 0) {
        newsList.value = res.data
        if (res.data.pos1.length > 0) {
          bigImgData.value = res.data.pos1[0]
          if (res.data.pos1.length > 1 && res.data.pos1.length < 5) {
            bulletsData.value = res.data.pos1.slice(1, 5)
          } else {
            bulletsData.value = res.data.pos1.slice(1, res.data.pos1.length)
          }
        }
        if (res.data.pos2.length > 0) {
          asideoneImg.value = res.data.pos2[0]
        }
        if (res.data.pos2.length > 1 && res.data.pos2.length < 5) {
          asidebulletsData.value = res.data.pos2.slice(1, 4)
        } else {
          asidebulletsData.value = res.data.pos2.slice(1, res.data.pos2.length)
        }
        if (res.data.pos3.length > 0) {
          asideArticleData.value = res.data.pos3.slice(0, 4)
        }
        if (res.data.pos4.length > 0) {
          botfullData.value = res.data.pos4.slice(0, res.data.pos4.length)
          const leg1 = res.data.pos4.length
          if (leg1 > 0) {
            botfullData.value[0].secondary = mdList.value.slice(4, 7)
          }
          if (leg1 > 1) {
            botfullData.value[1].secondary = mdList.value.slice(7, 10)
          }
          if (leg1 > 2) {
            botfullData.value[2].secondary = mdList.value.slice(10, 13)
          }
          if (leg1 > 3) {
            botfullData.value[4].secondary = mdList.value.slice(13, 16)
          }
          if (leg1 > 4) {
            botfullData.value[4].secondary = mdList.value.slice(16, 19)
          }
          if (leg1 > 5) {
            botfullData.value[5].secondary = mdList.value.slice(19, 21)
          }
          if (leg1 > 6) {
            botfullData.value[6].secondary = mdList.value.slice(21, 24)
          }
          isTextBc.value = true
        }
      }
    })

}

</script>

<style scoped lang="scss"></style>
